package com.yufubao.api.controller.applet.product;


import com.yufubao.framework.annotation.SystemLog;
import com.yufubao.framework.result.ResponseResult;
import com.yufubao.model.pojo.applet.product.SupplierInfoEntity;
import com.yufubao.service.service.applet.product.SupplierInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;


/**
 * 商家申请表
 *
 * @author zhangzhan
 * @email 52194440@qq.com
 * @date 2024-08-26 21:11:22
 */
@Api("商家申请")
@RestController
@RequestMapping("/applet/supplierInfo")
public class SupplierInfoController {
    @Autowired
    private SupplierInfoService supplierInfoService;



    /**
     * 商户删除店信息
     * TODO 商家提现等操作？
     */
    @RequestMapping(value = "/deleteInfo/{supplierInfoId}", method = RequestMethod.DELETE)
    @ApiOperation(value = "商户删除店信息")
    @SystemLog(info = "商户删除店信息")
    public ResponseResult deleteInfo(@PathVariable("supplierInfoId") Long supplierInfoId) {
        return supplierInfoService.deleteInfo(supplierInfoId);
    }

    /**
     * 商户修改店基本信息（门照/封面）
     */
    @RequestMapping(value = "/updateCover/{supplierInfoId}", method = RequestMethod.PUT)
    @ApiOperation(value = "商户修改店基本信息（门照/封面）")
    @SystemLog(info = "商户修改店基本信息（门照/封面）")
    public ResponseResult updateCover(@PathVariable("supplierInfoId") Long supplierInfoId,
                                      @RequestParam("shopFrontUrl") String shopFrontUrl) {
        return supplierInfoService.updateCover(supplierInfoId, shopFrontUrl);
    }

    /**
     * 商户修改营业状态
     */
    @RequestMapping(value = "/updateHolidayState/{supplierInfoId}", method = RequestMethod.PUT)
    @ApiOperation(value = "商户修改营业状态")
    @SystemLog(info = "商户修改营业状态")
    public ResponseResult updateHolidayState(@PathVariable("supplierInfoId") Long supplierInfoId,
                                             @RequestParam("holidayState") String holidayState) {
        return supplierInfoService.updateHolidayState(supplierInfoId, holidayState);
    }





    /**
     * 信息
     */
    @RequestMapping(value = "/info/{supplierInfoId}", method = RequestMethod.GET)
    @ApiOperation(value = "信息")
    public ResponseResult info(@PathVariable("supplierInfoId") Long supplierInfoId) {
        SupplierInfoEntity supplierApply = supplierInfoService.getById(supplierInfoId);

        return ResponseResult.okResultPage("SupplierApply", supplierApply);
    }

    /**
     * 保存
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiOperation(value = "保存")
    public ResponseResult save(@RequestBody SupplierInfoEntity supplierApply) {
        supplierInfoService.save(supplierApply);

        return ResponseResult.ok();
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @ApiOperation(value = "修改")
    public ResponseResult update(@RequestBody SupplierInfoEntity supplierApply) {
        supplierInfoService.updateById(supplierApply);

        return ResponseResult.ok();
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除")
    public ResponseResult delete(@RequestBody Long[] supplierInfoIds) {
        supplierInfoService.removeByIds(Arrays.asList(supplierInfoIds));

        return ResponseResult.ok();
    }

}
